﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADONETDataServicesExtension.Utils;

namespace ADONETDataServicesExtension.Parsing
{
    public class ExpressionLexer : FrameworkEncapsulatedType<object>
    {
        internal const string FrameworkTypeName = "System.Data.Services.Parsing.ExpressionLexer";

        public ExpressionLexer(object expressionLexer)
            : base(expressionLexer)
        {
        }

        public int Position
        {
            get
            {
                return ReflectionHelper.GetProperty<int>(FrameworkTypeName, "Position", FrameworkObject);
            }
        }

        public void ValidateToken(int t)
        {
            ReflectionHelper.InvokeVoidMethod(FrameworkTypeName, "ValidateToken", FrameworkObject, t);
        }

        public void NextToken()
        {
            ReflectionHelper.InvokeVoidMethod(FrameworkTypeName, "NextToken", FrameworkObject);
        }

        public string ExpressionText
        {
            get
            {
                return ReflectionHelper.GetProperty<string>(FrameworkTypeName, "ExpressionText", FrameworkObject);
            }
        }

        public static bool IsNumeric(int id)
        {
            return ReflectionHelper.InvokeStaticMethod<bool>(FrameworkTypeName, "IsNumeric", id);
        }

        public Token PeekNextToken()
        {
            return ReflectionHelper.Convert(ReflectionHelper.InvokeMethod(FrameworkTypeName, "PeekNextToken", FrameworkObject), frameworkValue => new Token(frameworkValue));
        }

        public Token CurrentToken
        {
            get
            {
                return ReflectionHelper.Convert(ReflectionHelper.GetProperty(FrameworkTypeName, "CurrentToken", FrameworkObject), frameworkValue => new Token(frameworkValue));
            }
            set
            {
                ReflectionHelper.SetProperty(FrameworkTypeName, "CurrentToken", FrameworkObject, value == null ? null : value.FrameworkObject);
            }
        }
    }
}
